package lembrete.core.report;

import java.util.Iterator;
import java.util.List;

import lembrete.core.beans.Entrada;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

public class RelatorioAgendaDataSource implements JRDataSource {

	private Iterator itrEntrada;

    private Object valorAtual;

    private boolean irParaProximaEntrada = true;
	
	public RelatorioAgendaDataSource(List entradas){
		 super();
	     this.itrEntrada = entradas.iterator();
	}
	
	public boolean next() throws JRException {
		 valorAtual = itrEntrada.hasNext() ? itrEntrada.next() : null;
		 irParaProximaEntrada = (valorAtual != null);
		 return irParaProximaEntrada;
	}
	
	public Object getFieldValue(JRField field) throws JRException {
		Object valor = null;
        Entrada entrada = (Entrada) valorAtual;

        if ("nome".equals(field.getName())) {
            valor = entrada.getNome();
        } else if ("telefone".equals(field.getName())) {
            valor = entrada.getTelefone();
        } else if ("dataDeAniversario".equals(field.getName())) {
            valor = entrada.getAniversario();
        } 

        return valor;
	}

	

}
